﻿using System.Linq.PageList;
using Dyao.Book.Contract;

namespace Dyao.Book.Application.Abstractions
{
    public interface ITaskCenterRecordApplication
    {

        /// <summary>
        /// 获取任务记录
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task<TaskCenterRecordInfoDto> GetCenterRecordInfoModelAsync(int id, CancellationToken cancellationToken = default);

        /// <summary>
        /// 是否有当前任务正在运行
        /// </summary>
        /// <param name="settingId">taskId</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task<bool> IsHaveCurrentTaskRunningAsync(string settingId, CancellationToken cancellationToken = default);

        /// <summary>
        /// 当前用户是否有正在运行的任务
        /// </summary>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task<bool> IsCurrentUserHaveRunningTaskAsync(CancellationToken cancellationToken = default);

        /// <summary>
        /// 获取任务记录
        /// </summary>
        /// <param name="pageFilter">pageFilter</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task<PageList<TaskCenterRecordPageDto>> GetTaskCenterRecordModelPagedListAsync(IPageFilter<TaskCenterRecordFilterDto, TaskCenterRecordOrderByDto> pageFilter, CancellationToken cancellationToken = default);

        /// <summary>
        /// 删除任务记录
        /// </summary>
        /// <param name="taskCenterRecordDeleteModel">taskCenterRecordDeleteModel</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task DeleteAsync(TaskCenterRecordDeleteDto taskCenterRecordDeleteModel, CancellationToken cancellationToken = default);

        /// <summary>
        /// 验证同一用户同一任务时间间隔
        /// </summary>
        /// <param name="taskSettingId">任务Id</param>
        /// <param name="intervalSeconds">间隔秒数</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task<bool> HaveRecordAsync(string taskSettingId, int intervalSeconds, CancellationToken cancellationToken = default);

        /// <summary>
        /// 自动检查重试
        /// </summary>
        /// <param name="defaultTimeoutMinutes">默认超时分钟</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task AutoCheckAndRetryAsync(int defaultTimeoutMinutes, CancellationToken cancellationToken = default);

        /// <summary>
        /// 检查超时任务
        /// </summary>
        /// <param name="taskCenterCheckRetryModel">taskCenterCheckRetryModel</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task UpdateTimeoutAsync(TaskCenterCheckRetryDto taskCenterCheckRetryModel, CancellationToken cancellationToken = default);

        /// <summary>
        /// 重试超时任务
        /// </summary>
        /// <param name="taskCenterCheckRetryModel">taskCenterCheckRetryModel</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task RetryTimeoutAsync(TaskCenterCheckRetryDto taskCenterCheckRetryModel, CancellationToken cancellationToken = default);

        /// <summary>
        /// 删除已完成的任务记录
        /// </summary>
        /// <param name="deleteRecordTypeEnum">删除记录类型</param>
        /// <param name="preHour">删除前多少小时</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task DeleteCompleteAsync(DeleteRecordTypeEnum deleteRecordTypeEnum, int preHour, CancellationToken cancellationToken = default);

        /// <summary>
        /// 获取扩展表执行信息内容
        /// </summary>
        /// <param name="recordId">recordId</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task<string> GetRecordExtensionExcutingInfoAsync(int recordId, CancellationToken cancellationToken = default);

        /// <summary>
        /// 获取扩展表结果信息内容
        /// </summary>
        /// <param name="recordId">recordId</param>
        /// <param name="cancellationToken">cancellationToken</param>
        /// <returns></returns>
        Task<string> GetRecordExtensionResultAsync(int recordId, CancellationToken cancellationToken = default);
    }
}
